package com.opencloud.iot.provider.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.opencloud.common.model.PageParams;
import com.opencloud.iot.client.model.entity.IotBeacons;
import com.opencloud.iot.client.model.entity.IotDaySleepResult;
import com.opencloud.iot.client.model.entity.IotNStreng;
import com.opencloud.iot.provider.controller.IotDaySleepResultController;
import com.opencloud.iot.provider.mapper.IotBeaconsMapper;
import com.opencloud.iot.provider.mapper.IotDaySleepResultMapper;
import com.opencloud.iot.provider.service.IotBeaconsService;
import com.opencloud.iot.provider.service.IotDaySleepResultService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 动量服务
 * @author yeyong
 */

@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class IotDaySleepResultServiceImpl implements IotDaySleepResultService {
    @Autowired
    private IotDaySleepResultMapper iotDaySleepResultMapper;

    /**
     * 获取每日睡眠信息
     * @param watchmac
     * @param slpstatus
     * @param thisdate
     * @return
     */
    @Override
    public List<IotDaySleepResult> findListPage(String watchmac,Integer slpstatus,String thisdate) {
        QueryWrapper<IotDaySleepResult> queryWrapper = new QueryWrapper();
        queryWrapper.lambda().eq(ObjectUtils.isNotEmpty(thisdate),IotDaySleepResult::getThisdate,thisdate);
        queryWrapper.lambda().eq(ObjectUtils.isNotEmpty(watchmac),IotDaySleepResult::getWatchmac,watchmac);
        queryWrapper.lambda().eq(slpstatus>=0,IotDaySleepResult::getSlpstatus,slpstatus);
        //queryWrapper.lambda().between(ObjectUtils.isNotEmpty(StartDate) && ObjectUtils.isNotEmpty(EndDate),IotDaySleepResult::getThisdate, StartDate, EndDate);
        queryWrapper.lambda().orderByDesc(IotDaySleepResult::getCreatetime);
        return iotDaySleepResultMapper.selectList(queryWrapper);
    }

    @Override
    public Integer addIotDaySleepResult(IotDaySleepResult entiy)
    {
        return iotDaySleepResultMapper.insert(entiy);
    }

    @Override
    public Integer updateIotDaySleepResult(IotDaySleepResult entiy)
    {
        return iotDaySleepResultMapper.updateById(entiy);
    }

    @Override
    public IotDaySleepResult getIotDaySleepResultById(Integer id){
        return iotDaySleepResultMapper.selectById(id);
    }

}
